<template>
	<view v-show="focus">
		<view class="footer" :style="{'bottom':bottom+'px'}">
			<view class="footer-center">
				<input class="input-text" type="text" @confirm="sendMessge" v-model="content" :focus="focus" @blur="blur"
				 :placeholder="placeholder" @focus="inputFocus" :adjust-position="false"></input>
			</view>
			<view class="footer-right">
				<view id='msg-type' class="send-comment" @tap="sendMessge">发送</view>
			</view>
		</view>
		<view class="tui-popup-mask tui-mask-show" v-if="mask" @tap="handleClose"></view>
	</view>
</template>

<script>
	export default {
		name: "chat-input",
		data() {
			return {
				content: '',
				bottom: 0,
				focus: false,
				placeholder: '',
				commObject: {}
			}
		},
		props: {
			//是否需要mask
			mask: {
				type: Boolean,
				default: true
			}
		},
		methods: {
			blur: function() { //失焦触发通知父组件
				this.handleClose()
			},
			sendMessge: function() {
				if (!this.content) {
					uni.showModal({
						content: "还没有输入内容哦!",
						showCancel: false
					})
					return;
				}
				var that = this;
				//点击发送按钮时，通知父组件用户输入的内容
				this.commObject.content = this.content;
				this.$emit('send-message', this.commObject);
				that.content = ''; //清空上次输入的内容
				this.focus = false;
			},
			inputFocus(e) {
				setTimeout(() => {
					this.bottom = (e.detail.height - 4)
				}, 50)
			},
			handleClose() {
				setTimeout(() => {
					this.$emit('blur')
					this.focus = false;
					this.bottom = 0
				}, 50)
			},
			open(e) {
				this.content = '';
				this.placeholder = '评论';
				if (e.type == 'card') {
					if (e.content) this.content = e.content || ''
				} else if (e.type == 'comm') {
					if (e.buserid) {
						if (e.content) this.content = e.content || ''
						this.placeholder = `回复${e.usernick}`
					}
				}
				this.commObject = JSON.parse(JSON.stringify(e))
				this.$nextTick(() => {
					this.focus = true;
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.footer {
		position: fixed;
		left: 0upx;
		bottom: 0upx;
		z-index: 99999999;
		display: flex;
		flex-direction: row;
		width: 100%;
		height: 90upx;
		min-height: 90upx;
		border-top: solid 1px #bbb;
		overflow: hidden;
		padding: 5upx;
		background-color: #F4F5F6;
	}

	.footer-left {

		width: 80upx;
		height: 80upx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.footer-right {
		width: 120upx;
		height: 80upx;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #1482D1;
	}

	.footer-center {
		flex: 1;
		padding-left: 20upx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.footer-center .input-text {
		flex: 1;
		background: #fff;
		/* border: solid 1upx #ddd; */
		padding: 10upx !important;
		font-family: verdana !important;
		overflow: hidden;
		height: 60upx;
		border-radius: 15upx;
		margin: 20upx 0upx;
	}

	.footer-right .send-comment {
		background-color: $indexColor;
		text-align: center;
		line-height: 60upx;
		color: #FFFFFF;
		width: 90upx;
		height: 60upx;
		border-radius: 5px;
		font-size: 10px;
		margin: 20upx 0upx;
		/* height: 60upx; */
	}

	.tui-popup-mask {
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		bottom: 0;
		background: transparent;
		z-index: 999;
		transition: all 0.3s ease-in-out;
		opacity: 0;
		visibility: hidden;
	}

	.tui-mask-show {
		opacity: 1;
		visibility: visible;
	}
</style>
